package com.lanou.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.lanou.entity.Book;
import com.lanou.entity.PageInfo;
import com.lanou.mapper.BookMapper;
import com.lanou.service.BookService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;

@Service
public class BookServiceImpl implements BookService {
    @Resource
    private BookMapper bookMapper;

    @Override
    public PageInfo list(PageInfo pageInfo, String sort, String order) {
        Page<Object> p = PageHelper.offsetPage(pageInfo.getOffset(), pageInfo.getLimit());
        bookMapper.findAll(sort, order);

        pageInfo.setRows(p.getResult());
        pageInfo.setTotal(p.getTotal());

        return pageInfo;
    }

    @Override
    @Transactional
    public int add(Book book) {
        return bookMapper.insert(book);
    }

    @Override
    @Transactional
    public int del(int bid) {
        return bookMapper.del(bid);
    }
}

